package com.vichat.task;

import com.alibaba.dubbo.container.spring.SpringContainer;
import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.signal.CmdUtil;
import com.vichat.common.vo.PageFilter;
import com.vichat.room.entity.RoomBasic;
import com.vichat.room.entity.RoomMember;
import com.vichat.room.service.IRoomService;
import com.vichat.task.service.ITask;
import com.vichat.user.entity.UserBasic;
import com.vichat.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Created by ranjx on 2018/06/29.
 * 获取过期频道，执行频率凌晨03：00
 */
@Component("ExpireUserTask")
public class ExpireUserTask implements ITask {
    private static transient final Logger logger = LoggerFactory.getLogger(ExpireUserTask.class);
    private IUserService userService;

    @Override
    public String doTask(long cfgTaskId) throws Exception {
        ApplicationContext ctx = SpringContainer.getContext();
        userService = (IUserService) ctx.getBean("userService", IUserService.class);
        UserBasic queryBean = new UserBasic();
        queryBean.setStartDate(new Date());
        List<UserBasic> roomBasics = userService.queryExpiredUser();
        if (!roomBasics.isEmpty()) {
            for (UserBasic val : roomBasics) {
                logger.info("发送过期用户消息:" + val.getUserName() + ",编号:" + val.getUid());
                CmdUtil.sendImMsg(10000, val.getUid(), 0, GlobalConstant.IMS_REMOVE_STOP, "");
            }
        }
        return null;
    }
}
